package com.navi.loaddata.loadService.impl.Dcdata;

import com.navi.loaddata.core.errorLog.ErrorCode;
import com.navi.loaddata.core.etlException.ETLException2;
import com.navi.loaddata.core.mesEntity.SpcDcResultData;
import com.navi.loaddata.core.mesEntity.SpcDcdata;
import com.navi.loaddata.core.mysqlEntity.EtlConfDModel;
import com.navi.loaddata.core.oracleEntity.EtlPdsGlassSummaryV;
import com.navi.loaddata.core.oracleEntity.EtlPdsGlassV;
import com.navi.loaddata.core.oracleEntity.EtlPdsResultV;
import com.navi.loaddata.core.util.ProcessUtil;
import com.navi.loaddata.loadService.impl.Dcdata.array.ProcessDcDataServiceARRAY3;
import com.navi.loaddata.loadService.impl.Dcdata.cell1.ProcessDcDataServiceCELL13;
import com.navi.loaddata.loadService.impl.Dcdata.cell2.ProcessDcDataServiceCELL23;
import com.navi.loaddata.loadService.impl.Dcdata.cf.ProcessDcDataServiceCF3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author jay
 */
@Service
public class ProcessDcDataService {
    private static final Logger logger = LoggerFactory.getLogger(ProcessDcDataService.class);
    @Autowired
    private ProcessDcDataServiceARRAY3 processDcDataServiceARRAY3;
    @Autowired
    private ProcessDcDataServiceCF3 processDcDataServiceCF3;
    @Autowired
    private ProcessDcDataServiceCELL13 processDcDataServiceCELL13;
    @Autowired
    private ProcessDcDataServiceCELL23 processDcDataServiceCELL23;

    public EtlPdsGlassV processDcData(EtlConfDModel etlConfD, SpcDcdata spcDcdata) throws Exception {
        EtlPdsGlassV etlPdsGlassV = new EtlPdsGlassV();
        switch (etlConfD.getShop()){
            case "ARRAY":
                etlPdsGlassV=processDcDataServiceARRAY3.processDcData(spcDcdata);
                break;
            case "CF":
                etlPdsGlassV=processDcDataServiceCF3.processDcData(spcDcdata);
                break;
            case "OC":
                if("CELL1".equals(etlConfD.getCellType())){
                    etlPdsGlassV=processDcDataServiceCELL13.processDcData(spcDcdata);
                }else if("CELL2".equals(etlConfD.getCellType())){
                    etlPdsGlassV=processDcDataServiceCELL23.processDcData(spcDcdata);
                }
                break;

        }
        return etlPdsGlassV;
    }

    public EtlPdsGlassSummaryV processPdsGlassSummary(EtlPdsGlassV etlPdsGlassV, String paramCollection, SpcDcResultData firstResult) {
        EtlPdsGlassSummaryV etlPdsGlassSummaryV=new EtlPdsGlassSummaryV();
        try{
            etlPdsGlassSummaryV.setStepId(etlPdsGlassV.getStepId());
            etlPdsGlassSummaryV.setSubEquipId(etlPdsGlassV.getSubEquipId());
            etlPdsGlassSummaryV.setGlassId(etlPdsGlassV.getGlassId());
            etlPdsGlassSummaryV.setGlassEndTime(etlPdsGlassV.getGlassEndTime());
            etlPdsGlassSummaryV.setParamCollection(paramCollection);//TODO
            etlPdsGlassSummaryV.setParamName(firstResult.getItemname());
        }catch (Exception e){
            throw new ETLException2(ErrorCode.ERROR_PROCESS_MES2ORA_PDS_GLASS_SUMMARY,e);
        }
        return etlPdsGlassSummaryV;
    }

    public EtlPdsResultV processPdsResultData(EtlConfDModel etlConfD, SpcDcdata spcDc, String paramCollection, SpcDcResultData curResult) {
        EtlPdsResultV result=new EtlPdsResultV();
        try {
                    result.setStepId(spcDc.getProcessoperationname());
                    result.setSubEquipId(spcDc.getUnitname());
                    result.setGlassId(spcDc.getMaterialname());
                    result.setGlassEndTime(spcDc.getEventtime());
                    result.setParamCollection(paramCollection);
                    result.setParamName(curResult.getItemname());
                    result.setSiteName(curResult.getSitename());
                    result.setParamValue(ProcessUtil.getDouble(curResult.getResult()));
        }catch (Exception e){
            throw new ETLException2(ErrorCode.ERROR_PROCESS_MES2ORA_PDS_GLASS_RESULT,e);
        }
        return result;
    }
}
